$(function () {
    $("#jqGrid").Grid({
        url: '../incomecoinconfig/list',
        colModel: [
            {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
            {label: '币数量', name: 'value', index: 'value', width: 30},
            {label: '规则', name: 'rule', index: 'rule', width: 80},
            {label: '普通倍数', name: 'multiple', index: 'multiple', width: 30},
            {label: '状态', name: 'status', index: 'status', width: 40 ,
                formatter: function (value) {
                    if (value == 1) {
                        return "启用";
                    } else if (value == 0) {
                        return "关闭";
                    }
                    return "其他";
                }},
            {
                label: '类型', name: 'type', index: 'type', width: 40,
                formatter: function (value) {
                    if (value == 1) {
                        return "普通用户邀请注册";
                    } else if (value == 2) {
                        return "普通用户运动";
                    } else if (value == 3) {
                        return "D-one产品";
                    }else if (value == 4) {
                        return "D-one用户运动";
                    }else if (value == 5) {
                        return "新用户注册";
                    }else if (value == 6) {
                        return "D-one用户邀请";
                    }else if (value == 7) {
                        return "任务配置";
                    }else if (value == 8) {
                        return "兑换产品消费";
                    }else if (value == 11) {
                        return "普通用户运动挖矿";
                    }else if (value == 12) {
                        return "D-one用户运动挖矿";
                    }else if(value==13){
                        return "SPC转账";
                    }else if(value==14){
                        return "产品奖励倍数";
                    }else if(value==15){
                        return "每天能量释放";
                    }else if(value==16){
                        return "D-one推荐11人释放能量";
                    }else if(value==17){
                        return "D-one推荐111人释放能量";
                    }else if(value==18){
                        return "D-one推荐333人赠送代理商";
                    }else if(value==19){
                        return "普通用户推荐50能量 奖励30 释放20;D-one翻倍";
                    }else if(value==20){
                        return "普通用户推荐3人50能量 奖励40 释放30;D-one翻倍";
                    }else if(value==21){
                        return "每日闪兑比例";
                    }
                    return "其他";
                }
            },

            // {label: '最短距离', name: 'minLength', index: 'minLength', width: 80},
            {label: '最长距离', name: 'maxLength', index: 'maxLength', width: 30},
            {label: '最大数量', name: 'maxNum', index: 'maxNum', width: 30},
            {label: '最小单位', name: 'minNum', index: 'minNum', width: 30},
            {label: '满数量', name: 'num', index: 'num', width: 30},
            {
                label: '创建日期', name: 'createdDate', index: 'createdDate', width: 80,
                formatter: function (value) {
                    return transDate(value);
                }
            }]
    });
});

let vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        tIncomeCoinConfig: {},
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.tIncomeCoinConfig = {};
        },
        update: function (event) {
            let id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            let url = vm.tIncomeCoinConfig.id == null ? "../incomecoinconfig/save" : "../incomecoinconfig/update";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.tIncomeCoinConfig),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            let ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    url: "../incomecoinconfig/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../incomecoinconfig/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.tIncomeCoinConfig = r.tIncomeCoinConfig;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            let page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                name: ''
            }
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        }
    }
});